package team093;

import battlecode.common.*;
import static battlecode.common.GameConstants.*;


public class RobotPlayer implements Runnable {

	private final RobotController myRC;

	public RobotPlayer(RobotController rc) {
		myRC = rc;
	}

	public void run() {
		switch(myRC.getRobotType()) {
			case ARCHON: archon(); break;
			case SOLDIER: soldier(); break;
			case SNIPER: sniper(); break;
			case MORTAR: mortar(); break;
			case SCOUT: scout(); break;
			case BOMBER: bomber(); break;
		}
	}
	
	private void archon() {
		while (true) {
			try {
				while (myRC.isMovementActive())
					myRC.yield();
				
				if (myRC.canSpawn() && myRC.getEnergonLevel() >= RobotType.SOLDIER.spawnCost() && myRC.canMove(myRC.getDirection()))
				{
					myRC.setIndicatorString(0, "I am spawning.");
					myRC.spawn(RobotType.SOLDIER);
				}
				else {
					myRC.setIndicatorString(0, "I failed spawning, so moving.");
					if (myRC.canMove(myRC.getDirection()))
						myRC.moveForward();
					else
						myRC.setDirection(myRC.getDirection().rotateRight());
				}
				
				myRC.yield();
			}
			catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	private void soldier() {
		while (true) {
			try {
				while (myRC.isMovementActive())
					myRC.yield();
				
				if (myRC.canMove(myRC.getDirection()))
					myRC.moveForward();
				else
					myRC.setDirection(myRC.getDirection().rotateRight());
				
				myRC.yield();
			}
			catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	private void sniper() {
		while(true) {
			try {
				//TODO: do it
			}
			catch(Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	private void mortar() {
		while(true) {
			try {
				//TODO: do it
			}
			catch(Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	private void scout() {
		while(true) {
			try {
				//TODO: do it
			}
			catch(Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	private void bomber() {
		while(true) {
			try {
				//TODO: do it
			}
			catch(Exception e) {
				e.printStackTrace();
			}
		}
	}
	
//	private void tower() {
//		while(true)
//			myRC.yield();
//	}

}
